package edu.gdkm.sql.dao;
import edu.gdkm.sql.pojo.OrderDetail;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface OrderDetailMapper {

    // Create
    @Insert("INSERT INTO orderdetail (orderid, productid, count) VALUES (#{orderid}, #{productid}, #{count})")
    int insertOrderDetail(OrderDetail orderDetail);

    // Update
    @Update("UPDATE orderdetail SET orderid = #{orderid}, productid = #{productid}, count = #{count} WHERE id = #{id}")
    int updateOrderDetail(OrderDetail orderDetail);

    // Read
    @Select("SELECT * FROM orderdetail WHERE id = #{id}")
    OrderDetail getOrderDetailById(int id);

    @Select("SELECT * FROM orderdetail")
    List<OrderDetail> getAllOrderDetails();

    // 新添加的方法：根据orderid查询orderdetail
    @Select("SELECT * FROM orderdetail WHERE orderid = #{orderid}")
    List<OrderDetail> getOrderDetailsByOrderId(int orderid);
    // Delete
    @Delete("DELETE FROM orderdetail WHERE id = #{id}")
    int deleteOrderDetail(int id);
}